<?php

namespace Summer\Hjd\Http\Controllers;

use Illuminate\Routing\Controller;
use RLuders\JWTAuth\Classes\JWTAuth;
use Summer\Hjd\Classes\CommonApi;
use Summer\Hjd\Http\Requests\WdRecordCreateRequest;
use Summer\Hjd\Models\BonusRecordModel;
use Summer\Hjd\Models\WalletModel;
use Summer\Hjd\Models\WdRuleModel;
use Summer\Hjd\Models\WdRecordModel;
use Summer\Hub\Http\Controllers\Traits\ApiReturn;
use Input;
use Config;
use Db;
use Exception;
use System\Models\File as FileModel;


class BonusRecordController extends Controller
{
    use ApiReturn;

    /**
     * 奖金记录
     */
    public function index(JWTAuth $auth)
    {
        if (!$user = $auth->user()) {
            return $this->apiError('登录失效,请重新登录');
        }
        //佣金余额
        $currency_slug='bonus';
        $balance=WalletModel::where('currency_slug',$currency_slug)->where('user_id',$user->id)->value('balance');

        $page=Input::get('page',1);
        $page_size=Input::get('page_size',20);
        $query=BonusRecordModel::select();
        $query->where('user_id',$user->id);
        $query->orderBy('id','DESC');
        $records=$query->paginate($page_size,$page);
        $records->each(function ($record){
            $record->bonus_type_text=$record->bonus_type->title;
        });
        $return['balance']=$balance;
        $return['records']=$records;
        return $this->apiSuccess('操作成功',$return);
    }
}
